import 'dart:ffi';

class DeviceModel {
  String id;
  DateTime date;
  String? appVersion;
  String? systemInfo;

  String? userAgreementVersion;
  String? privacyAgreementVersion;
  String? guideVersion;

  DeviceModel({
    required this.id,
    required this.date,
    this.appVersion,
    this.systemInfo,
    this.userAgreementVersion,
    this.privacyAgreementVersion,
    this.guideVersion,
  });

  factory DeviceModel.fromJson(Map<String, dynamic> json) {
    return DeviceModel(
      id: json['id'],
      date: DateTime.fromMillisecondsSinceEpoch(
          json['date'] is Int ? json['date'] : json['date'].toInt()),
      appVersion: json['appVersion'],
      systemInfo: json['systemInfo'],
      userAgreementVersion: json['userAgreementVersion'],
      privacyAgreementVersion: json['privacyAgreementVersion'],
      guideVersion: json['guideVersion'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'date': date.millisecondsSinceEpoch,
      if (appVersion != null) 'appVersion': appVersion,
      if (systemInfo != null) 'systemInfo': systemInfo,
      if (userAgreementVersion != null)
        'userAgreementVersion': userAgreementVersion,
      if (privacyAgreementVersion != null)
        'privacyAgreementVersion': privacyAgreementVersion,
      if (guideVersion != null) 'guideVersion': guideVersion,
    };
  }
}
